<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: 和
  Date: 2020/10/21
  Time: 8:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:useBean id="user" class="com.media.bean.UserBean"></jsp:useBean>
<jsp:setProperty name="user" property="*"></jsp:setProperty>
<%
    //加载数据库驱动
    Class.forName("com.mysql.jdbc.Driver" ) ;

    //建立数据库连接
    String url="jdbc:mysql://localhost:3306/mxy";//数据库链接地址
    Connection connection= DriverManager.getConnection(url,"root","root");//第一个数据库用户名  第二个密码


    String sql="select * from whd where username=? and password=? and gender=? and age=?  and ";//在PreparedStatement中使用？代替实际参数
    PreparedStatement ps =connection.prepareStatement(sql);

    ps.setString(1,user.getUsername());
    ps.setString(2,user.getPassword());
    ps.setInt(3,user.getGender());
    ps.setInt(4,user.getAge());
    ps.setInt(5,user.getId());

    int count =ps.executeUpdate();

    if (count>0){
        out.print("修改成功");
    }else{
        out.print("修改失败");
    }
    response.setHeader("refresh","3;url=home.jsp");

%>